<?php


namespace app\data\model;


use think\admin\Model;

class DataDeviceSettings extends Model
{
    //更新设备上报属性
    function setting($iotId,$data){
        $fieldsList  = $this->getTableFields();
        $model_data = [];
        foreach ($data as $key=>$item){
            if (in_array($key, $fieldsList)) {
                $model_data[$key]=is_array($item['value'])?json_encode($item['value']):$item['value'];
            }
        }
        if(!empty($model_data)){
            $count = $this->where(['iot_id'=>$iotId])->count();
            if($count>0){
                $this->where(['iot_id'=>$iotId])->update($model_data);
            }else{
                $model_data['iot_id']=$iotId;
                $this->insert($model_data);
            }
        }
    }
}
